-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
util: add JoinQueue data structure #7590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
2068e58
to
bab83ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should replicate most of the methods from JoinSet
.
2c34aef
to
837875d
Compare
Ok, I pushed implementation of all methods except |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is not the double-ended queue, I would suggest change it to another name.
/// | ||
/// [`join_next`]: fn@Self::join_next | ||
/// [`JoinError::id`]: fn@tokio::task::JoinError::id | ||
pub async fn join_all(mut self) -> Vec<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All async functions must have a cancel safety section in the documentation.
// A JoinHandle generally won't emit a wakeup without being ready unless | ||
// the coop limit has been reached. We yield to the executor in this | ||
// case. | ||
cx.waker().wake_by_ref(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong because self.0.front_mut()
is not the same as the pop_notified()
used by JoinSet
. Since you always poll a JoinHandle
no matter what, you should not call wake_by_ref()
here. This will cause needless spinning.
Please add a test that would have caught this bug. You can look at tests using tokio_test::spawn
for examples of how you can detect whether wakeups are sent.
New
tokio_util::task::JoinQueue
structure as FIFO-ordered analog oftokio::task::JoinSet
.Issue: #7576
Edit: renamed from
JoinDeque
toJoinQueue
.